#include "elk_web_delegate.h"
#include "internals/elk_browser_client.h"

ElkWebDelegate::ElkWebDelegate(QObject *parent) :
    QObject(parent)
{

}

ElkWebDelegate::~ElkWebDelegate()
{

}

bool ElkWebDelegate::isNull() const
{
    return handler_.isNull();
}

void ElkWebDelegate::createAsChild(QWidget *parent)
{
    if (!handler_) {
        handler_.reset(new ElkBrowserClient(this, parent->winId(), 0, 0, parent->width(), parent->height()));
    }
}

void ElkWebDelegate::setFocus()
{
    if (handler_) {
        handler_->SetFocus(true);
    }
}

void ElkWebDelegate::clearFocus()
{
    if (handler_) {
        handler_->SetFocus(false);
    }
}

void ElkWebDelegate::resize(const QSize &size)
{
    if (handler_) {
        handler_->SetPosition(0, 0, size.width(), size.height());
    }
}

void ElkWebDelegate::resize(int width, int height)
{
    if (handler_) {
        handler_->SetPosition(0, 0, width, height);
    }
}

void ElkWebDelegate::load(const QString &url)
{
    if (handler_) {
        handler_->Load(url);
    }
}

void ElkWebDelegate::stopLoad()
{
    if (handler_) {
        handler_->StopLoad();
    }
}

void ElkWebDelegate::reload()
{
    if (handler_) {
        handler_->Reload();
    }
}

void ElkWebDelegate::reloadIgnoreCache()
{
    if (handler_) {
        handler_->ReloadIgnoreCache();
    }
}
